package com.csun.nusing.ui.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.csun.nusing.R;
import com.csun.nusing.bean.jsonbean.OldrestStateJsonBean.OldrestStateDataBean;

import java.util.List;

/**
 * 适用于viewpager ClassName: CustomPagerAdapter
 * 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-30
 */
public class CustomPagerAdapter extends PagerAdapter {
	private List<OldrestStateDataBean> mTabList;
	private Context context;
	private View convertView;

	public CustomPagerAdapter(Context context,
			List<OldrestStateDataBean> tabList) {
		this.context = context;
		this.mTabList = tabList;
	}

	@Override
	public View instantiateItem(ViewGroup container, int position) {
		viewHolder viewHolder = null;
		// 重用convertView
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_nursing_oldrest_list, null);
			viewHolder = new viewHolder();
			viewHolder.bloodoxyTv = convertView
					.findViewById(R.id.item_viewpager_bloodoxy_tv);
			viewHolder.bloodpressTv = convertView
					.findViewById(R.id.item_viewpager_bloodpress_tv);
			viewHolder.bloodsugerTv = convertView
					.findViewById(R.id.item_viewpager_bloodsuger_tv);
			viewHolder.heartrateTv = convertView
					.findViewById(R.id.item_viewpager_heartrate_tv);
			viewHolder.huxiTv = convertView
					.findViewById(R.id.item_viewpager_huxi_tv);
			viewHolder.temperatureTv = convertView
					.findViewById(R.id.item_viewpager_temperature_tv);
			viewHolder.photoimageView = convertView
					.findViewById(R.id.item_viewpager_headphoto_iv);
			viewHolder.nameTv = convertView
					.findViewById(R.id.item_viewpager_name_tv);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (viewHolder) convertView.getTag();
		}
		// 操作
		if (mTabList.get(position) != null) {
			if (mTabList.get(position).getHeadpicture() != null) {
				Glide.with(context)
						.load(mTabList.get(position).getHeadpicture())
						.into(viewHolder.photoimageView);
			}
			viewHolder.bloodoxyTv.setText(""
					+ mTabList.get(position).getBoxvygenStatus());
			viewHolder.bloodpressTv.setText(""
					+ mTabList.get(position).getBpressureStatus());
			viewHolder.bloodsugerTv.setText(""
					+ mTabList.get(position).getBsugarStatus());
			viewHolder.heartrateTv.setText(""
					+ mTabList.get(position).getHeartrateStatus());
			viewHolder.huxiTv.setText(""
					+ mTabList.get(position).getBreatheStatus());
			viewHolder.temperatureTv.setText(""
					+ mTabList.get(position).getTemperatureStatus());
			viewHolder.nameTv.setText("" + mTabList.get(position).getOldName());

		}
		container.addView(convertView);
		return convertView;
	}

	@Override
	public int getCount() {
		return mTabList.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {

		return view == object;
	}

	@Override
	public CharSequence getPageTitle(int position) {
		return mTabList.get(position).getOldName();
	}

	private class viewHolder {
		public ImageView photoimageView;
		public TextView nameTv;
		public TextView bloodoxyTv;
		public TextView heartrateTv;
		public TextView bloodpressTv;
		public TextView temperatureTv;
		public TextView bloodsugerTv;
		public TextView huxiTv;
	}

}